<?php

$IDUserOnline = elgg_get_logged_in_user_guid();
$idLesson = (int) $_SESSION["idLesson"];
$write = new Write();

$post = (bool) get_input('post');
$tagFriend = (bool) get_input('tagFriend');

if ($tagFriend) {
    $myfriends = get_user_friends($IDUserOnline);
    $myTagedFriend = "";



    foreach ($myfriends as $friend) {
        $id = $friend->getID();
        $check = get_input($id);
        if ($check == $id) {
            $myTagedFriend .= $check . " ";
        }
    }

    if ($myTagedFriend != "") {
        $write->SaveMyTagFriend($myTagedFriend, $IDUserOnline, $idLesson);
        system("Tag friend Success!");
    }
}

if ($post) {

//    $myfriend = get_user_friends_objects($IDUserOnline);
//    $myfriend2 = get_user_friends($IDUserOnline);

    $Content = (string) get_input('Content');
    $result = $write->updateContentWrite($IDUserOnline, $idLesson, $Content);

    if ($result)
    {
        system("luu bai viet thanh cong");
    //Lưu xuống csdl đã học từ vựng


    $status = new Status();
    $status->SetStatusWriting($IDUserOnline, $idLesson);
//End Lưu xuống csdl đã học từ vựng
    }
    else
    system("bi loi roi");
}
?>
